#include <iostream>

const int QueueSize = 10;

class ArrayQueue
{
public:
    ArrayQueue() : front(0), rear(0)
    {
    }
    void Push(const int &element)
    {
        // if (rear == QueueSize)
        if ((rear + 1) % QueueSize == front) // rear和front差了一个位置
        {
            std::cout << "队列满" << std::endl;
            return;
        }
        a[rear++] = element;
        rear %= QueueSize;
    }
    // 出队列
    void Pop()
    {
        if (front == rear)
        {
            std::cout << "队列空" << std::endl;
            return;
        }
        front++;
        front %= QueueSize;
    }

    int *GetFront() // 取队头元素
    {
        if (front == rear)
        {
            std::cout << "队列空" << std::endl;
            return nullptr;
        }
        return &a[front];
    }
    
    bool IsEmpty()
    {
        return front == rear;
    }

private:
    int a[QueueSize];
    int front;
    int rear;
};

int main()
{
    ArrayQueue q;
    for (int i = 0; i < 10; i++)
    {
        q.Push(i + 1);
    }
    while (q.IsEmpty() == false)
    {
        std::cout << *q.GetFront() << " ";
        q.Pop();
    }
    std::cout << std::endl;
    q.Push(1);
    q.Push(2);
    while (q.IsEmpty() == false)
    {
        std::cout << *q.GetFront() << " ";
        q.Pop();
    }
    std::cout << std::endl;
    return 0;
}
